package com.cy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@RestController
@RequestMapping("/consumer/template")
public class RestConsumerController {
    @Autowired
    private RestTemplate LoadBalanceRestTemplate;

    @DeleteMapping("{id}")
    public String doDelete(@PathVariable Integer id){
        String url =
                String.format("http://%s/provider/template/%s",
                        "nacos-provider",id);
        LoadBalanceRestTemplate.delete(url);
        return "delete ok";
    }

    @PostMapping
    public Map<String,Object> doPost(@RequestBody Map<String,Object> map){
        String url =
                String.format("http://%s/provider/template/",
                        "nacos-provider");
        return LoadBalanceRestTemplate.postForObject(url,
                map,    //传入的数据
                Map.class); //返回的类型
    }

    @PutMapping
    public String doPut(@RequestBody Map<String,Object> map){
        String url =
                String.format("http://%s/provider/template/","nacos-provider");
        LoadBalanceRestTemplate.put(url,map);
        return "put ok";
    }
}
